package com.gxuwz.PangGuangyao.business.action.web;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.gxuwz.PangGuangyao.business.entity.SysRepair;
import com.gxuwz.PangGuangyao.business.service.ISysRepairService;
import com.gxuwz.core.pagination.Result;
import com.gxuwz.core.web.action.BaseAction;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

public class SysRepairAction extends BaseAction implements Preparable, ModelDriven {

	
	private static final long serialVersionUID = -2025587568675799563L;
	
	protected static final String LIST_JSP = "/WEB-INF/page/web/SysRepair_list.jsp";
	protected static final String ADD_JSP = "/WEB-INF/page/web/SysRepair_add.jsp";
	protected static final String EDIT_JSP = "/WEB-INF/page/web/SysRepair_edit.jsp";
	protected static final String APPLY_ADD_JSP = "/WEB-INF/page/web/SysRepairApply.jsp";
	
	protected final Log logger=LogFactory.getLog(getClass());
	
	private Result<SysRepair> pageResult; //分页
	private SysRepair sysRepair;
	@Autowired
	private ISysRepairService sysRepairService;
	
	@Override
	public void prepare() throws Exception {
		if(null == sysRepair){
			sysRepair = new SysRepair();
		}
		
	}

	public String list()throws Exception{
		String logtype = getRequest().getParameter("logtype");
		getRequest().getSession().setAttribute("logtype", logtype);
		pageResult=sysRepairService.findAll(getPage(), getRow(),logtype);
		forwardView = LIST_JSP;
		return SUCCESS;
	}

	public String add() throws Exception{
		sysRepairService.add(sysRepair);
		return list();
	}
	
	 //跳转到添加页面
	 public String openAddApply(){
		 forwardView=APPLY_ADD_JSP;
		 return SUCCESS;
	 }

	public String update() throws Exception{
		sysRepairService.update(sysRepair.getId());
		return list();
	}
	
	public String delete() throws Exception{
		sysRepairService.delete(sysRepair.getId());
		return list();
	}
	

	public String openList(){
		
		return SUCCESS;
	}

	public String openAdd(){
		forwardView = ADD_JSP;
		return SUCCESS;
	}

	public String openEdit(){
		sysRepair = sysRepairService.findById(sysRepair.getId());
		forwardView = EDIT_JSP;
		return SUCCESS;
	}
	
	
	@Override
	public Object getModel() {
		
		return sysRepair;
	}


	public Result<SysRepair> getPageResult() {
		return pageResult;
	}

	public void setPageResult(Result<SysRepair> pageResult) {
		this.pageResult = pageResult;
	}

	public SysRepair getSysweixiu() {
		return sysRepair;
	}

	public void setSysRepair(SysRepair sysRepair) {
		this.sysRepair = sysRepair;
	}	


	
}
